/**
 * @author hejl
 * @date on 2018/10/13.
 */
window.onload = function (ev) {
    topbar.hide();
};

$('#dataTable').bootstrapTable({
    url: '/UserWithdrawBankController/queryBankCodeMap',
    height: $(window).height() - 200,
    pageSize: 30,
    pagination: true,
    pageList: [30, 50, 100],
    clickToSelect: true,
    singleSelect: true,
    queryParams: queryParams,
    queryParamsType: '',
    sidePagination: 'server',
    responseHandler: function (res) {
        return {
            //总页数
            "total": res.total,
            //数据
            "rows": res.rows
        };
    },
    columns: [[
        {
            checkbox: true
        },
        {
            width: '2px',
            align: 'center',
            formatter: function (v, row, index) {
                return index + 1
            }
        },
        {
            title: '',
            field: 'id',
            visible: false,
            width: 100,
            align: 'center'
        }, {
            title: '支付方式',
            field: 'payBank',
            width: 100,
            align: 'center'
        }, {
            title: '银行名称',
            field: 'bankName',
            width: 150,
            align: 'center'
        },
        {
            title: '银行类型',
            field: 'bankAccountType',
            width: 150,
            align: 'center'
        },
        {
            align: 'center', field: 'bankCode', width: 150, title: '银行编码'
        }
    ]]
});

$("#search").click(function () {
    $("#dataTable").bootstrapTable("refresh");
});

$("#addBankCodeMap").click(function () {
    $("#addWithdrawBankForm").form("clear");
    $("#editPayBank").removeAttr("readonly")
    $("#editBankAccountType").val("对私");
    $("#updateUserModalLabel").text("新增银行卡");
    $("#addWithdrawBankModel").modal("show");
})

$("#editBankCodeMap").click(function () {
    var rows = $('#dataTable').bootstrapTable("getSelections");
    if (rows === null || rows === '' || rows.length === 0) {
        layer.msg("请选择要操作的数据");
        return;
    }
    $("#updateUserModalLabel").text("修改银行卡");
    var bankName = rows[0].bankName;
    var bankCode = rows[0].bankCode;
    var bankAccountType = rows[0].bankAccountType;
    var payBank = rows[0].payBank;
    var bankId = rows[0].id;
    $("#addWithdrawBankForm").form("clear");
    $("#editPayBank").val(payBank);
    $("#editPayBank").attr("readonly","readonly")
    $("#editBankName").val(bankName);
    $("#bankId").val(bankId);
    $("#editBankAccountType").val(bankAccountType);
    $("#bankCode").val(bankCode);
    $("#addWithdrawBankModel").modal("show");
})

/**
 * 添加银行卡信息
 */
function addWithdrawBankCode() {
    if ($("#bankId").val() != "") {
        $.post("UserWithdrawBankController/updateBankCodeMap", $("#addWithdrawBankForm").serialize(), function (data) {
            if (data.success) {
                $("#dataTable").bootstrapTable("refresh");
                $("#addWithdrawBankModel").modal("hide");
                layer.msg(data.message);
            } else {
                $("#addWithdrawBankModel").modal("hide");
                layer.msg(data.message);
            }
        });
    } else {
        $.post("UserWithdrawBankController/insertBankCodeMap", $("#addWithdrawBankForm").serialize(), function (data) {
            if (data.success) {
                $("#dataTable").bootstrapTable("refresh");
                $("#addWithdrawBankModel").modal("hide");
                layer.msg(data.message);
            } else {
                $("#addWithdrawBankModel").modal("hide");
                layer.msg(data.message);
            }
        });
    }

}

function queryParams(params) {
    return {
        pageSize: params.pageSize,
        pageNumber: params.pageNumber,
        bankName: $("#bankName").val(),
        bankAccountType: $("#bankAccountType").val(),
        payBank: $("#payBank").val(),
    };
}





